package ch.sv7.tool.dbmanager.db.fix;

import ch.sv7.tool.dbmanager.db.ForeignKeySchema;
import ch.sv7.tool.dbmanager.db.SchemaElement;
import ch.sv7.tool.dbmanager.db.dialect.DialectException;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class RenameForeignKeyFix extends AbstractSchemaFix implements SchemaFix {


	private ForeignKeySchema actualForeignKeySchema;
	private ForeignKeySchema expectedForeignKeySchema;

	/**
	 * @param actualIndexSchema
	 * @param expectedIndexSchema
	 */
	public RenameForeignKeyFix(ForeignKeySchema actualForeignKeySchema, ForeignKeySchema expectedForeignKeySchema) {
		super();
		this.actualForeignKeySchema = actualForeignKeySchema;
		this.expectedForeignKeySchema = expectedForeignKeySchema;
	}

	public SchemaElement getActionTarget() {
		return expectedForeignKeySchema;
	}
	
	public String getSQLFix() throws DialectException {
		String ddl = "\n-- Rename foreign key Fix \n";
		ddl += getDialect().getRenameForeignKeyDDL(actualForeignKeySchema, expectedForeignKeySchema.getName());
		return ddl;
	}

	public int getPriority() {
		return SchemaFix.PRIORITY_FOREIGN_KEY_RENAME;
	}

	public String getDescription() {
		return "Rename foreign key " + actualForeignKeySchema.getTableSchema().getName() + "." + actualForeignKeySchema.getName() + " to " + expectedForeignKeySchema.getName();
	}

	public int getAction() {
		return ACTION_EDIT;
	}

	
}
